/*
 *  SineWaveTable.cpp
 *  SoundController0002
 *
 *  Created by jiro on 10/11/22.
 *  Copyright 2010 jiro music. All rights reserved.
 *
 */


#include "SineWaveTable.h"

namespace sc
{
	SineWaveTable::SineWaveTable( double frequency, double phaseShift, double adjuster )
	  : WaveTable( WaveTable::Type_Sine, frequency, adjuster ),
		phaseShift( phaseShift )
	{}

	SineWaveTable::~SineWaveTable()
	{}

	bool SineWaveTable::operator == ( const WaveTable& rhs ) const
	{
		if ( ! this->WaveTable::operator == ( rhs ) ) {
			return false;
		}
		const SineWaveTable& ref = dynamic_cast< const SineWaveTable& >( rhs );
		return phaseShift == ref.phaseShift;
	}

	bool SineWaveTable::operator != ( const WaveTable& rhs ) const
	{
		return not( *this == rhs ); 
	}
	
	bool SineWaveTable::operator < ( const WaveTable& rhs ) const
	{
		if ( type != rhs.GetType() ) {
			return type < rhs.GetType();
		}
		if ( ! this->WaveTable::operator == ( rhs ) ) {
//		if ( this->WaveTable::operator < ( rhs ) ) {
			return true;
		}
		const SineWaveTable& ref = dynamic_cast< const SineWaveTable& >( rhs );
		return phaseShift < ref.phaseShift;
	}

	double SineWaveTable::operator [] ( double time ) const 
	{
		return WaveTable::adjuster * std::sin( 2.0 * Pi * time * WaveTable::frequency + 2.0 * Pi * phaseShift );
	}

}
